import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQml.Models

XPopWindow {
    id:_mainWindow
    flags:  Qt.Dialog
    comTitle:Item{}
    defaultTitleHight:0
    visible: true
    width: 440
    height: 280
    title: "XPowerCalculator"

    signal btnClicked(var data)

    QtObject{
        id:_publicSetting
        property int radius: 10
        property int numWidth: 100
        property int numHeight: 35
        property int btnRowCount: 4
    }


    comClient: Item{
        Item{
            anchors.fill:parent
            anchors.margins: 20
            Label{
                id:_labelShow
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.bottom: _btnGridView.top

                Connections{
                    target: _mainWindow
                    function onBtnClicked(data){
                        if(data === "="){
                            _labelShow.text = xCalcManage.calc(_labelShow.text)
                        }
                        else{
                            _labelShow.text += data
                        }
                    }
                }
            }

            GridView{
                id:_btnGridView
                anchors.left: parent.left
                anchors.right: parent.right
                height: _publicSetting.btnRowCount * _publicSetting.numHeight
                anchors.bottom: parent.bottom
                cellWidth: _publicSetting.numWidth
                cellHeight: _publicSetting.numHeight

                model:ListModel{
                    ListElement{
                        btnShow:"7"
                        btnData:"7"
                    }
                    ListElement{
                        btnShow:"8"
                        btnData:"8"
                    }
                    ListElement{
                        btnShow:"9"
                        btnData:"9"
                    }
                    ListElement{
                        btnShow:"*"
                        btnData:"*"
                    }


                    ListElement{
                        btnShow:"4"
                        btnData:"4"
                    }
                    ListElement{
                        btnShow:"5"
                        btnData:"5"
                    }
                    ListElement{
                        btnShow:"6"
                        btnData:"6"
                    }
                    ListElement{
                        btnShow:"-"
                        btnData:"-"
                    }

                    ListElement{
                        btnShow:"1"
                        btnData:"1"
                    }
                    ListElement{
                        btnShow:"2"
                        btnData:"2"
                    }
                    ListElement{
                        btnShow:"3"
                        btnData:"3"
                    }
                    ListElement{
                        btnShow:"+"
                        btnData:"+"
                    }

                    ListElement{
                        btnShow:"/"
                        btnData:"/"
                    }
                    ListElement{
                        btnShow:"0"
                        btnData:"0"
                    }
                    ListElement{
                        btnShow:"."
                        btnData:"."
                    }
                    ListElement{
                        btnShow:"="
                        btnData:"="
                    }
                }

                delegate: XRoundButton{
                    //            radius:_publicSetting.radius
                    width: _btnGridView.cellWidth
                    height:_btnGridView.cellHeight
                    text:btnShow
                    onClicked:_mainWindow.btnClicked(btnData)
                }

            }

        }

    }




}
